event_comment=
{
    commentLoading: false,
    commentPosting: false,
    commentPage: 0,
    firstTime: true,
	insertSymbol: function(symbol)
	{
		var obj=$('#comment_content').get(0);
		if (document.selection)
		{
			obj.focus();
			sel = document.selection.createRange();
			sel.text = symbol;
		}
		else if (obj.selectionStart || obj.selectionStart == 0)
		{
			var startPos = obj.selectionStart;
			var endPos = obj.selectionEnd;
			obj.value = obj.value.substring(0, startPos)
						+ symbol
						+ obj.value.substring(endPos, obj.value.length);
		} 
		else
		{
			obj.value += symbol;
		}
	},
	loadComment:  function(eid, p)
 	{
 	    if (this.commentLoading)
 	    {
 	        return false;
 	    }

 	    $.ajax({
			   type: "GET",
			   url: "/event/comment/view/" + eid + "?page=" + p,
			   beforeSend: function(req){
                   $("#cmt_loader").show();
				   event_comment.commentLoading=true;
			   },
		       complete: function(res, s){
		       	   
			       $("#comment_area").html(res.responseText);
				   $("#cmt_loader").hide();
				   
				   event_comment.commentLoading=false;
				   event_comment.commentPage=p;
				   if (!event_comment.firstTime)
				   {
                        location.href='#comment_section';
				   }
				   else
				   {
				        event_comment.firstTime=false;
				   }
				   
			    }	   
	        });
 		return false;
 	},
 	deleteComment: function(cid)
 	{
 		if (!confirm("Báº¡n cháº¯c cháº¯n xÃ³a bÃ¬nh luáº­n nÃ y"))
 			return false;
 		$.ajax({
			   type: "POST",
			   url: "/event/comment/delete/" + cid + "?page=" + this.commentPage,
			   error: function(req, status, info){
			   	   alert("CÃ³ lá»—i khi xÃ³a bÃ¬nh luáº­n. HÃ£y thá»­ láº¡i láº§n khÃ¡c");
			   },
			   success: function(comment, status){
			   	   $("#comment_area").html(comment);
			   	   location.href='#comment_section';
			   }
		});
		return false;
 	},
 	saveComment: function(eid, cid)
 	{
 		var saveCommentUrl = "/event/comment/save/" + eid;
 		if (cid == '') {
            textAreaID = "#comment_content";
        } else {            
            textAreaID = "#comment_content_" + cid;
            saveCommentUrl = saveCommentUrl+"/"+cid;
        }
        
 	    if ($(textAreaID).val()=="")
			return;
		if (event_comment.commentPosting)
			return;

		$.ajax({
			   type: "POST",
			   url: saveCommentUrl,
			   data: $(textAreaID).serialize(),
			   beforeSend: function(req){
                   $("#cmt_loader").show();
				   event_comment.commentPosting=true;
			   },
			   error: function(req, status, info){
			   	   alert("CÃ³ lá»—i khi cáº­p nháº­t bÃ¬nh luáº­n cá»§a báº¡n");
			   },
			   success: function(comment, status){
			   	   $("#comment_area").html(comment);
			   	   $(textAreaID).val("");
			   },
			   complete: function(res, s){
				   $("#cmt_loader").hide();
				   event_comment.commentPosting=false;
				   event_comment.commentPage=0;
				   location.href='#comment_section';
			    }
		});
 	},
 	showReplyBox: function(cid)
    {
        $("#reply_hint_" + cid).hide();
        $("#reply_box_" + cid).show();
        return false;
    },
    showReply: function(cid)
    {
        $('.reply_comment_' + cid).show();
        $('#display_reply_' + cid).hide();
        return false;
    }
}